package com.myWeb.servlet;

import com.myWeb.beans.User;
import com.myWeb.dao.IUserDao;
import com.myWeb.dao.impl.userDao;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;

//处理登录请求的servlet
public class CheckNameServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=UTF-8");
        IUserDao userDao = new userDao();
        System.out.println("ChecknameServlet");
        String username = req.getParameter("username");
        System.out.println(username);
        PrintWriter out = resp.getWriter();
        try {
            if(userDao.isExist(username)){
                out.println(true);
//                req.setAttribute("loginError", "该用户名已经注册过了哦~换一个名字试试!");// 设置错误属性
//                req.getRequestDispatcher("register.jsp").forward(req, resp);
            }else{
                out.println(false);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }

}
